//
//  ConfigureFocus.swift
//  HealthMonitoring
//
//  Created by YTYanK on 2018/7/19.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
/// 
class ConfigureFocus: HMTableViewController {
   
    var dataAry: Array<Any>!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        super.hideHeader()
        super.hideFooter()
    }
    override func load() {
        self.tableView.isScrollEnabled = false
        self.dataAry = ["消息通知","修改手机绑定","帮助","法律声明","登出"]
        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataAry.count
    }
     // cell 数据
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
    }
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    override func cellForRow(atIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) as UITableViewCell
        cell.textLabel?.text = self.dataAry[indexPath.row] as! String
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == (self.dataAry.count - 1) {
//            self.showConfirm(title: "xxxx", message: "ffffff")
            let optionMenu = UIAlertController.init(title: "是否退出当前用户？", message: nil, preferredStyle: .alert)
    
            let action = UIAlertAction.init(title: "退出", style: UIAlertActionStyle.destructive,  handler:{ (alert) in
                
              let app =  UIApplication.shared.delegate as! AppDelegate
                UIView.transition(with: app.window!, duration: 0.6, options: UIViewAnimationOptions.transitionFlipFromLeft, animations: {
                    let oldState = UIView.areAnimationsEnabled
                    UIView.setAnimationsEnabled(false)
                    app.switchLogin(showLogin: nil)
                   UIView.setAnimationsEnabled(oldState)
                    
                    
                    
                }, completion: nil)
                

                
                
            })
            
            let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel, handler:{ (alert) in
                print("取消")
            })
            
            optionMenu.addAction(action)
//            optionMenu.addAction(saveAction)
            optionMenu.addAction(cancelAction)
            
             self.present(optionMenu, animated: true, completion: nil)
            
        }else if indexPath.row == 1{
              let bind = Binding()
               bind.isChangeUI = true
             self.pushViewController(bind)
        }
    }
    
    
    
}
